// connection.cpp
// Copyright (C) 2008 Sam Bateman
// samuel.bateman@gmail.com
//
// This file is part of DVD On Fire.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

//! @file connection.cpp
//! @author Sam Bateman
//! @brief Source file for the Connection class.

#include <cstdio>
#include <string>
#include "connection.h"
using namespace std;

namespace dvdonfire
{
    namespace lib
    {
        // struct Connection::Impl {{{
        struct Connection::Impl
        {
        };
        // }}}
        // Connection::Connection() {{{
        //! @brief Constructor.
        Connection::Connection()
        {
            impl = new Impl;
        }
        // }}}
        // Connection::~Connection() {{{
        //! @brief Destructor.
        Connection::~Connection()
        {
            delete impl;
        }
        // }}}
        // Connection::isRunning() {{{
        //! @brief Returns whether the daemon is running.
        //! @return True is dvdonfire-daemon is running, false otherwise.
        bool Connection::isRunning()
        {
            // get the pid of the daemon
            string pid_file = "~/.dvdonfire/dvdonfire-daemon.pid";
            FILE *fp = fopen(pid_file.c_str(), "r");
            if (!fp) return false;
            int pid;
            fscanf(fp, "%d", &pid);
            printf("pid = %d\n", pid);
            fclose(fp);

            return true;
        }
        // }}}
    }
}
